package coml.jiyun.hp.reviewtopic.ui.activity;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import java.util.ArrayList;

import butterknife.BindView;
import coml.jiyun.hp.reviewtopic.R;
import coml.jiyun.hp.reviewtopic.base.BaseActivity;
import coml.jiyun.hp.reviewtopic.bean.NaviBean;
import coml.jiyun.hp.reviewtopic.presenter.NaviPresenter;
import coml.jiyun.hp.reviewtopic.ui.adapter.FlowNaviAdapter;
import coml.jiyun.hp.reviewtopic.view.NaviView;
import qdx.stickyheaderdecoration.NormalDecoration;

public class NaviActivity extends BaseActivity<NaviPresenter>implements NaviView {

    @BindView(R.id.navi_rlv)
    RecyclerView mNaviRlv;
    private ArrayList<NaviBean.DataBean> dataBeans;
    private FlowNaviAdapter flowNaviAdapter;

    @Override
    protected NaviPresenter initPresenter() {
        return new NaviPresenter();
    }

    @Override
    protected void initListener() {

    }

    @Override
    protected void initData() {
        mPresenter.getNavi();
    }

    @Override
    protected void initView() {

        mNaviRlv.setLayoutManager(new LinearLayoutManager(this));
        dataBeans = new ArrayList<>();
        flowNaviAdapter = new FlowNaviAdapter(this, dataBeans);
        mNaviRlv.setAdapter(flowNaviAdapter);

        NormalDecoration decoration = new NormalDecoration() {
            @Override
            public String getHeaderName(int i) {
                return dataBeans.get(i).getName();
            }
        };
        mNaviRlv.addItemDecoration(decoration);
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_navi;
    }

    @Override
    public void setNavi(NaviBean naviBean) {
       if (naviBean != null && naviBean.getData() != null && naviBean.getData().size() > 0){
           flowNaviAdapter.addData(naviBean.getData());
           flowNaviAdapter.notifyDataSetChanged();
       }
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }
}
